﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AppAds_API.BLL.Interface;
using AppAds_API.BLL.Model;
using AppAds_API.BLL.DbModel;

namespace AppAds_API.BLL.Repository
{
    public class AdsRepository : IAdsRepository
    {
        AdsDataBaseEntities _context = new AdsDataBaseEntities();

        public Ad Add(Ad item)
        {
            
            return item;
        }

        public List<Ad> GetAllAds()
        {
            var ads = (from a in _context.RealEstates
                      select new Ad()
                      {
                          AdId = a.Id,
                          AdTitle = a.Title,
                          AdDetail = a.Description,
                          AdType = a.Type
                      }).ToList();
            return ads;
        }

        public List<Ad> GetAdsByType(string type)
        {
            return (from a in _context.RealEstates
                   select new Ad(){
                       AdId = a.Id,
                       AdTitle = a.Title,
                       AdDetail = a.Description,
                       AdType = a.Type
                   }).ToList();
        }

        public Ad GetAdById(int id)
        {
            return (from a in _context.RealEstates
                   select new Ad()
                   {
                       AdId = a.Id,
                       AdTitle = a.Title,
                       AdDetail = a.Description,
                       AdType = a.Type
                   }).FirstOrDefault();
                   
        }

    }
}
